Posts

Post not yet marked as solved
2 Replies
This is the sample .geojson-file: "type": "FeatureCollection",                                                                                  "features": [ { "type": "Feature", "id": 0, "properties": { "AssetID": "2430-0051536", "Owner": "PDXTRANS", "MaintResp": "PGE", "LocationID": "BF58671", "ImagePath": null, "PowerSuppl": "PGE", "IsMetered": null, "Engineer": "NotAssigned", "Electricia": "NotAssigned", "LightID": 198761, "ElectricMo": 34481, "StLightCir": 0, "Rotation": 0.0, "LIP": null, "SupplyVolt": null, "Manufactur": null, "SerialNumb": null, "LampCode": "86", "LampCodeDe": "25,500-L,250-W,HPS,COBRA HEAD - POWER DOOR", "MastArmLen": 16, "PoleNumber": 413000054 }, "geometry": { "type": "Point", "coordinates": [ -122.713348173023704, 45.456437213860397 ] } } } ] }
Post not yet marked as solved
2 Replies
This Code should run in SwiftUI please:     override func viewDidLoad() {         super.viewDidLoad()         let map = MKMapView(frame: view.bounds)         map.autoresizingMask = .FlexibleWidth | .FlexibleHeight         view.addSubview(map)         var annotations = NSMutableArray()         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {             let pointData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("3000", ofType: "geojson")!)             let points = NSJSONSerialization.JSONObjectWithData(pointData!,                 options: nil,                 error: nil) as NSDictionary             for point in points["features"] as NSArray {                 let coordinate = (point["geometry"] as NSDictionary)["coordinates"] as NSArray                 let lon = coordinate[0] as CLLocationDegrees                 let lat = coordinate[1] as CLLocationDegrees                 let a = MKPointAnnotation()                 a.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)                 annotations.addObject(a)             }             dispatch_async(dispatch_get_main_queue()) {                 map.addAnnotations(annotations)                 map.showAnnotations(map.annotations, animated: false)             }         }     } }
Post not yet marked as solved
3 Replies
import MapKit struct MapView: UIViewRepresentable {     var coordinate: CLLocationCoordinate2D          let landmarks = LandmarkAnnotation.requestMockData()        func makeUIView(context: Context) -> MKMapView {         MKMapView(frame: .zero)     }               func updateUIView(_ view: MKMapView, context: Context) {         let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)         let region = MKCoordinateRegion(center: coordinate, span: span)         view.setRegion(region, animated: true)         /         view.addAnnotations(landmarks)     } } struct MapView_Previews: PreviewProvider {     static var previews: some View {         MapView(coordinate: landmarkData[0].locationCoordinate)              } }
Post not yet marked as solved
3 Replies
struct LandmarkDetail: View {          var landmark: Landmark          var body: some View {                  VStack{                 MapView(coordinate: landmark.locationCoordinate)                                 .edgesIgnoringSafeArea(.top)                 .frame(height: 300)                          CircleImage(image: landmark.image)                 .offset(x: 0, y: -130)                 .padding(.bottom, -130)               VStack(alignment: .leading) {                 Text(landmark.name)                     .font(.title)                 HStack(alignment: .top) {                     Text(landmark.park)                         .font(.subheadline)                     Spacer()                     Text(landmark.state)                         .font(.subheadline)                 }             }             .padding()             Spacer()         }         .navigationBarTitle(Text(landmark.name), displayMode: .inline)     } } struct LandmarkDetail_Previews: PreviewProvider {     static var previews: some View {         LandmarkDetail(landmark: landmarkData[0])     } }
Post not yet marked as solved
3 Replies
         let title: String?     let subtitle: String?     let coordinate: CLLocationCoordinate2D                      init(title:      String?,                      subtitle:   String?,                      coordinate: CLLocationCoordinate2D)                      {self.title = title                       self.subtitle = subtitle                       self.coordinate = coordinate}          static func requestMockData()-> [LandmarkAnnotation]{            return [               LandmarkAnnotation(title: "Aachen",                                   subtitle: "Karls Dom",                                   coordinate: .init(latitude: 50.774910, longitude: 6.083951)),                LandmarkAnnotation(title: "Vaals",                                   subtitle: "Aachens `kleine Schwerster` in den Niederlanden",                                   coordinate: .init(latitude: 50.773437, longitude: 6.016159)),                LandmarkAnnotation(title: "Köln",                                   subtitle: "Dom",                                   coordinate: .init(latitude: 50.941278, longitude: 6.958281)),                LandmarkAnnotation(title: "Ponttor",                                     subtitle: "Teil der ehemlaigen Stadtmauer",                                     coordinate: .init(latitude: 50.781770, longitude: 6.078248)),                LandmarkAnnotation(title: "Dreiländereck",                                   subtitle: "NE,BE, D",                                   coordinate: .init(latitude: 50.754482, longitude: 6.020776))                         ]        } }